package com.baichang.taoshunda.dao.impl;

import org.springframework.stereotype.Repository;

import com.baichang.framework.dao.impl.BaseDaoImpl;
import com.baichang.taoshunda.dao.InvoiceDao;
import com.baichang.taoshunda.entity.Invoice;

import java.util.List;
import java.util.Map;

@Repository
public class InvoiceDaoImpl extends BaseDaoImpl<Invoice> implements InvoiceDao {
    /**
     * 修改发票信息
     *
     * @param invoiceHead
     * @param invoiceNumber
     * @param invoiceType
     * @param invoiceId
     * @return
     */
    @Override
    public boolean updateInvoiceInfo(String invoiceHead, String invoiceNumber, Integer invoiceType, Integer invoiceId) {
        String sql = "UPDATE `t_invoice` SET `invoice_head`=?, `invoice_number`=?, `invoice_type`=? WHERE id=?";
        return update(sql, invoiceHead, invoiceNumber, invoiceType, invoiceId) > 0;
    }

    /**
     * 查询用户的全部的发票信息
     *
     * @param userId
     * @return
     */
    @Override
    public List<Map<String, Object>> findInvoiceList(Integer userId) {
        String sql = "SELECT f.id, f.user_id, f.invoice_head, f.invoice_number, f.invoice_type FROM t_invoice f WHERE f.user_id = ?";
        return queryForMapList(sql, userId);
    }

    /**
     * 查询用户的最新一条发票信息
     *
     * @param userId
     * @return
     */
    @Override
    public Map<String, Object> getInvoiceInfo(Integer userId) {
        String sql = "SELECT f.id, f.user_id, f.invoice_head, f.invoice_number, f.invoice_type FROM t_invoice f WHERE f.user_id = ? ORDER BY id DESC LIMIT 1";
        return queryForMap(sql, userId);
    }
}